﻿using System;
using SimpleServiceBus.Bus.MessageManagement;
using SimpleServiceBus.Bus.MessageManagement.MessageValueProviders;
using SimpleServiceBus.Bus.Pipeline;

namespace SimpleServiceBus.Configuration
{
    public static class MessageTypeManagementServiceExtensions
    {
        public static void RegisterMessageHeaderFor<TMessageType>(this IMessageTypeManagementService svc,
                                                                  string headerKey, string headerValueExpression)
        {
            svc.RegisterMessageHeaderFor<TMessageType>(headerKey,
                                                       new ExpressionMessageValueProvider(headerValueExpression));
        }

        public static void RegisterMessageHeaderFor<TMessageType>(this IMessageTypeManagementService svc,
                                                                  string headerKey,
                                                                  Func<TMessageType, string> headerValueProvider)
        {
            svc.RegisterMessageHeaderFor<TMessageType>(headerKey,
                                                       new DynamicMessageValueProvider<TMessageType>(headerValueProvider));
        }

        public static void RegisterMessageHeaderFor<TMessageType>(this IMessageTypeManagementService svc,
                                                                  string headerKey,
                                                                  Func<TMessageType, IMessageContext, string>
                                                                      headerValueProvider)
        {
            svc.RegisterMessageHeaderFor<TMessageType>(headerKey,
                                                       new DynamicMessageValueProvider<TMessageType>(headerValueProvider));
        }
    }
}